﻿using Humanizer;
using Microsoft.AspNetCore.Mvc;
using MVC_System.DTO.Location;
using MVC_System.DTO.Procured;
using MVC_System.DTO.RawMaterial;
using Newtonsoft.Json;
using NuGet.Common;
using WMS_MAV;

namespace MVC_System.Controllers
{
    /// <summary>
    /// 控制器
    /// </summary>
    public class RawMaterialController : Controller
    {
        private readonly IConfiguration _configuration;
        public RawMaterialController(IConfiguration configuration)
        {
            _configuration = configuration;
        }
        public IActionResult RawMaterialShow()
        {
            return View();
        }
        public IActionResult RawMaterialAdd()
        {
            return View();
        }
        public IActionResult RawMaterialUpdate()
        {
            return View();
        }


		public IActionResult RawmaterialtestingDetail()
		{
			return View();
		}
		public async Task<ActionResult> RawMaterShow(RawMaterialDTO dto)
        {
            HttpClientWrapper client = new HttpClientWrapper(dto.Token);
            string url = _configuration["Url"] + "RawApi/api/RawMaterials/RawMaterialShow?PageIndex=" + dto.pageIndex + "&PageSize=" + dto.pageSize + "&RawMaterialNumbering=" + dto.rawMaterialNumbering + "&RawMaterialName=" + dto.rawMaterialName + "&RawMaterilStatus=" + dto.rawMaterilStatus;
            var respomse = await client.GetAsync(url);
            return Json(respomse);
        }
        public async Task<ActionResult> RawMaterAdd(RawMaterialAddDTO dto)
        {
            HttpClientWrapper client = new HttpClientWrapper(dto.Token);
			string url = _configuration["Url"] + "RawApi/api/RawMaterials/RawMaterialAdd";
			var respomse = await client.PostAsync(url,dto.Data);
            return Json(respomse);
		}
        public async Task<ActionResult> RawMaterDelete(RawMaterialDeleteDTO dto,string token)
        {
			HttpClientWrapper client = new HttpClientWrapper(token);
			string url = _configuration["Url"] + "RawApi/api/RawMaterials/RawMaterialDelete";
			string list = JsonConvert.SerializeObject(dto);
			var respomse = await client.PostAsync(url, list);
			return Json(respomse);
		}
		public async Task<ActionResult> RawMaterDeletePi(RawMaterialDeletePiDTO dto,string token)
        {
			HttpClientWrapper client = new HttpClientWrapper(token);
			string url = _configuration["Url"] + "RawApi/api/RawMaterials/RawMaterialDeletePi";
			string list = JsonConvert.SerializeObject(dto);
			var respomse = await client.PostAsync(url, list);
			return Json(respomse);
		}
		public async Task<ActionResult> RawMaterMondel(RawMaterialMondelDTO dto)
		{
			HttpClientWrapper client = new HttpClientWrapper(dto.Token);
			string url = _configuration["Url"] + "RawApi/api/RawMaterials/RawMaterialMondel?id="+dto.rawMaterialId;
			var respomse = await client.GetAsync(url);
			return Json(respomse);
		}
		public async Task<ActionResult> RawMaterUpdate(RawMaterialUpdateDTO dto,string token)
		{
			HttpClientWrapper client = new HttpClientWrapper(token);
			string url = _configuration["Url"] + "RawApi/api/RawMaterials/RawMaterialUpdate";
			string list = JsonConvert.SerializeObject(dto);
			var respomse = await client.PostAsync(url, list);
			return Json(respomse);
		}
		/// <summary>
		/// 采购申请显示
		/// </summary>
		/// <returns></returns>
		public IActionResult ProcuredShow()
		{
			return View();
		}
        /// <summary>
        /// 采购申请显示列表
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<ActionResult> ProcuredShowsj(ProcuredShowDto dto)
        {
            HttpClientWrapper client = new HttpClientWrapper(dto.Token);
            string url = _configuration["Url"] + "LYH/api/Procured/ShowProcured?pageIndex=" + dto.pageIndex + "&pageSize=" + dto.pageSize + "&ProcuredNumber=" + dto.procuredNumber + "&ProcuredState=" + dto.procuredState + "&AddTime=" + dto.AddTime;
            var response = await client.GetAsync(url);
            return Json(response);
        }
        /// <summary>
        /// 采购申请添加视图
        /// </summary>
        /// <returns></returns>
        public IActionResult ProcuredAdd()
        {
            return View();
        }
        /// <summary>
        /// 采购申请添加
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ActionResult> ProcuredAddsj(ProcuredAddDto dto)
        {
            HttpClientWrapper client = new HttpClientWrapper(dto.Token);
            string url = _configuration["Url"] + "LYH/api/Procured/CreateProcured";
            var respomse = await client.PostAsync(url, dto.Data);
            return Json(respomse);
        }
        /// <summary>
        /// 采购申请修改
        /// </summary>
        /// <returns></returns>
        public IActionResult ProcuredUpdate()
        {
            return View();
        }
        /// <summary>
        /// 采购申请详情
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<ActionResult> ProcuredMondel(ProcuredIdDTO dto)
        {
            HttpClientWrapper client = new HttpClientWrapper(dto.Token);
            string url = _configuration["Url"] + "LYH/api/Procured/GetProcured?ProcuredId=" + dto.Id;
            var respomse = await client.GetAsync(url);
            return Json(respomse);
        }
        /// <summary>
        /// 采购申请修改
        /// </summary>
        /// <param name="dto"></param>
        /// <param name="token"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ActionResult> ProcuredUpdate(ProcuredUpdateDTO dto, string token)
        {
            HttpClientWrapper client = new HttpClientWrapper(token);
            string url = _configuration["Url"] + "LYH/api/Procured/UpdateLocation";
            string list = JsonConvert.SerializeObject(dto);
            var respomse = await client.PostAsync(url, list);
            return Json(respomse);
        }
        /// <summary>
        /// 采购申请删除
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost] 
        public async Task<ActionResult> ProcuredDelete(ProcuredAddDto dto)
        {
            HttpClientWrapper client = new HttpClientWrapper(dto.Token);
            string url = _configuration["Url"] + "LYH/api/Procured/DeleteLocation";
            var list = "{\"procuredId\":[" + dto.Data + "]}";
            var respomse = await client.PostAsync(url, list);
            return Json(respomse);
        }


        /// <summary>
        /// 采购申请查看视图(详情待采购)
        /// </summary>
        /// <returns></returns>
        public IActionResult ProcuredParticulars()
        {
            return View();
        }
        /// <summary>
        /// 采购申请查看视图(详情已采购)
        /// </summary>
        /// <returns></returns>
        public IActionResult ProcuredParticulars2()
        {
            return View();
        }
    }
}
